package com.lkm.market2_0.task;

import android.os.Looper;

import com.lkm.frame.task2.CTaskExecutor;
import com.lkm.market2_0.ExpandConfig;


public class DefaultTaskExecutor<P, PR, R > extends CTaskExecutor<P, PR, R> {

    private final boolean isHoldWakeLock;

    

    public DefaultTaskExecutor(Looper looper, boolean isHoldWakeLock) {
        super(ExpandConfig.instance.getTaskExecutor(), looper);
        this.isHoldWakeLock=isHoldWakeLock;
    }
    public DefaultTaskExecutor(boolean isHoldWakeLock) {
        this(Looper.getMainLooper(),isHoldWakeLock);
    }

    @Override
    public void onEnd(boolean isCancel, R r) {
        super.onEnd(isCancel, r);
    }

    @Override
    public void onPreExecute() {
        super.onPreExecute();
        if(this.isHoldWakeLock)
        ExpandConfig.instance.acquireWakeLock(0);
    }

    @Override
    public void onCancel() {
        super.onCancel();
        if(this.isHoldWakeLock)
            ExpandConfig.instance.releaseWakeLock();
    }

    @Override
    public void onFinish(R r) {
        super.onFinish(r);
        if(this.isHoldWakeLock)
            ExpandConfig.instance.releaseWakeLock();
    }

}